<?php
if(!Admin::checkPermission('canManageContent')) {
	General::ouputMessage('Fehler','Sie haben nicht gen&uuml;gend Rechte um diese Seite zu betrachten');
}else{
	
	if(isset($_POST['create'])) {
		DB::getInstance()->query("
			INSERT INTO
				".Tables::$contentExtensionsTbl."
			SET
				file = '".DB::parseVar($_POST['file'])."'");
	}


	if(isset($_GET['do']) && $_GET['do'] == "del" && isset($_GET['id']) && is_numeric($_GET['id'])) {
		DB::getInstance()->query("DELETE FROM ".Tables::$contentExtensionsTbl." WHERE id = '".$_GET['id']."'");
		General::ouputMessage("Erfolgreich!","Der Extension-Handler wurde gel&ouml;scht","form");
	}
			
			
	
	
	$content = array();
	$query = DB::getInstance()->query("SELECT id,file FROM ".Tables::$contentExtensionsTbl."");
	while($c = DB::getInstance()->fetchAssoc($query)) {
		$content[] = $c;
	}
	General::getTpl()->assign('ext',$content);
	
	
	// Files
	$files = array();
	$DH = dir("./kernel/contentExtensionHandler/");
	while ($extFile = $DH->read()) {
	   	if (preg_match('/^..?$/', $extFile)) continue;
		if(is_dir("./kernel/contentExtensionHandler/".$extFile)) continue;
		if($extFile == "extensionInterface.php" || $extFile == "DefaultHandler.php") continue;
		$exists = false;
		foreach($content as $c) {
			if(in_array($extFile,$c)) $exists = true;
		}
		if($exists) continue;
		
		$files[] = $extFile;
	}
	$DH->close();
	General::getTpl()->assign('files',$files);
	
	
	
	General::getTpl()->assign('body',
		General::getTpl()->fetch('../admin/content.html'));
}
?>